Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/target_libuv/roc_core/mutex.h
10//! @brief Mutex.
11
12#ifndef ROC_CORE_MUTEX_H_
13#define ROC_CORE_MUTEX_H_
14
15#include <uv.h>
16
18#include "roc_core/panic.h"
20
21namespace roc {
22namespace core {
23
24class Cond;
25
26//! Mutex.
27class Mutex : public NonCopyable<> {
28public:
29 //! RAII lock.
31
32 Mutex() {
33 if (int err = uv_mutex_init(&mutex_)) {
34 roc_panic("mutex: uv_mutex_init(): [%s] %s", uv_err_name(err),
35 uv_strerror(err));
36 }
37 }
38
39 ~Mutex() {
40 uv_mutex_destroy(&mutex_);
41 }
42
43 //! Lock mutex.
44 void lock() const {
45 uv_mutex_lock(&mutex_);
46 }
47
48 //! Unlock mutex.
49 void unlock() const {
50 uv_mutex_unlock(&mutex_);
51 }
52
53private:
54 friend class Cond;
55
56 mutable uv_mutex_t mutex_;
57};
58
59} // namespace core
60} // namespace roc
61
62#endif // ROC_CORE_MUTEX_H_
Condition variable.
Definition: cond.h:25
Mutex.
Definition: mutex.h:27
ScopedLock< Mutex > Lock
RAII lock.
Definition: mutex.h:30
void unlock() const
Unlock mutex.
Definition: mutex.h:49
void lock() const
Lock mutex.
Definition: mutex.h:44
Base class for non-copyable objects.
Definition: noncopyable.h:23
RAII mutex lock.
Definition: scoped_lock.h:21
Root namespace.
Non-copyable object.
Panic function.
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition: panic.h:42
RAII mutex lock.